#ifndef _TP_I2C_H_
#define _TP_I2C_H_

#include "stm32f4xx_hal.h"



#define TP_DRIVER_ADDR      0X15
#define TP_DRIVER_WRITE     TP_DRIVER_ADDR<<1 //0X2A
#define TP_DRIVER_READ      (TP_DRIVER_ADDR<<1)+1 //0X2B

//#define SOFT_I2C
#define HARD_I2C


#ifdef SOFT_I2C

#define TP_I2C_CTRL     GPIOB
#define TP_SCL_GPIO 	GPIO_PIN_10
#define TP_SDA_GPIO 	GPIO_PIN_3


#define TP_SCL_CLR  HAL_GPIO_WritePin(TP_I2C_CTRL, TP_SCL_GPIO, GPIO_PIN_RESET)
#define TP_SCL_SET  HAL_GPIO_WritePin(TP_I2C_CTRL, TP_SCL_GPIO, GPIO_PIN_SET)

#define TP_SDA_IN   GPIO_InitStruct.Pin = TP_SDA_GPIO;GPIO_InitStruct.Mode = GPIO_MODE_INPUT;GPIO_InitStruct.Pull = GPIO_PULLUP;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;HAL_GPIO_Init(TP_I2C_CTRL, &GPIO_InitStruct)
#define TP_SDA_Get  HAL_GPIO_ReadPin(TP_I2C_CTRL,TP_SDA_GPIO)

#define TP_SDA_OUT	GPIO_InitStruct.Pin = TP_SDA_GPIO;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_PULLUP;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;HAL_GPIO_Init(TP_I2TP_I2C_CTRLC_CTRL, &GPIO_InitStruct)
#define TP_SDA_CLR  HAL_GPIO_WritePin(TP_I2C_CTRL, TP_SDA_GPIO, GPIO_PIN_RESET)
#define TP_SDA_SET  HAL_GPIO_WritePin(TP_I2C_CTRL, TP_SDA_GPIO, GPIO_PIN_SET)

#else 
#ifdef HARD_I2C

#define TP_I2C_CTRL     GPIOB
#define TP_SCL_GPIO 	GPIO_PIN_10
#define TP_SDA_GPIO 	GPIO_PIN_3

#endif
#endif


uint32_t tp_i2c_read_len(uint8_t reg_addr, uint8_t *data, uint8_t len);
uint32_t tp_i2c_write_byte(uint8_t reg_addr, uint8_t data);


#endif